#pragma once
#include <iostream>
#include <unistd.h>
using namespace std;

typedef void (*work_t)(); // 函数指针类型
typedef void (*task_t)(); // 函数指针类型


void PrintLog()
{
    cout<<"输出任务"<<endl;
}

void ReloadConf()
{
    cout<<"Reload Conf"<<endl;
}

void ConnectMysql()
{
    cout<<"mysql task"<<endl;
}

task_t task[3] = {PrintLog,ReloadConf,ConnectMysql};

uint32_t NextTask()
{   
    return rand()%3;    
}

void worker()
{
    //从文件描述符为0的文件（已dup2为管道读端）中读取数据
    while (true)
    {
        uint32_t command_code = 0;//任务命令码，用于匹配任务
        ssize_t n = read(0,&command_code,sizeof(command_code));
        if(n == sizeof(command_code))
        {
            if(command_code >= 3)   continue;
            task[command_code]();
        }
        else if(n == 0)
        {
            std::cout<<"当前进程为："<<getgid()<<"立即退出"<<endl;
            break;
        }
    }
}